<?php
/*
 * 栏目分类控制器
 * @auth suosuo
 */
 namespace Home\Controller;
 use Think\Controller;
 
 class CatController extends CommonController {
 	public function index ()  {
 		$id = intval($_REQUEST['id']);
		if(!$id){
			return $this->error("id不合法或不存在");
		}
		$nav = D("Menu")->find($id);
		if(!$nav || $nav['status']!=1){
			return $this->error("栏目id不存在或状态不为正常");
		}
		$conds = array();
		$conds['catid'] = $id;
		$conds['status'] = 1;
		$page = $_GET['page'] ? $_GET['page'] : 1;
		$pageSize = 6;//每页显示数量
		$this->assign('webSiteMenu',D('Menu')->getBarMenus());
		$news = D('News')->getNews($conds,$page,$pageSize);
		$this->assign('catid',$conds['catid']);
		$this->assign('news',$news);
		
		$this->display();	
 	}
	
	
//	ajax获取文章列表
	public function getListAjax(){
		
		$catid = intval($_POST['catid']);
		$page = intval($_POST['start_num']);
		$pageSize = $_POST['pageSize'] ? $_POST['pageSize']:10;
		$conds = array(
			'catid'=>$catid,
			'status'=>1,
		);
		if(!$catid){
			return show(0, "栏目不存在");
		}
		$newsList = D('News')->getNewsByAjax ($conds,$page,$pageSize);
		if($newsList){
			if(sizeof($newsList)>0){
				return show(1, '有内容哦~',$newsList);
			}else{
				return show(0, '没有更多数据咯');
			}
			
		}
		return show(0, '没有更多数据了');
		
	}
	
 }
